package yb.ecp.fast.infra.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 * Created by liyuan on 2017/5/16.
 */
public class MathUtil {

    public static BigDecimal MathRount(BigDecimal value)
    {
       return new BigDecimal(Math.round(value.doubleValue()));
    }

    public static String MathRount(String value)
    {
        try {
            return Long.toString(Math.round(Double.parseDouble(value)));
        }
        catch (Exception exp)
        {
            return "0";
        }
    }

    public static double MathRount(double value)
    {
        return Math.round(value);
    }

    public static double MathRount(double value, int length)
    {
       return MathRount(new BigDecimal(value), length).doubleValue();
    }

    public static BigDecimal MathRount(BigDecimal value, int length)
    {
        return value.setScale(length, RoundingMode.HALF_EVEN);
    }
}
